﻿package com.kuanter.kuanterauto.adapter;

import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.entity.MessageInfo;

public class MyMessageAdapter extends BaseAdapter {
	private List<MessageInfo> messageInfos ;
	private Activity activity;
	private TextView msg_title_tv;
	private TextView msg_date_tv;
	
	public MyMessageAdapter(List<MessageInfo> messageInfos, Activity activity) {
		this.messageInfos = messageInfos;
		this.activity = activity;
	}
	
	public void deleteData(MessageInfo messageInfo){
		messageInfos.remove(messageInfo);
		this.notifyDataSetChanged();
	}

	@Override 
	public int getCount() {
		// TODO Auto-generated method stub
		return messageInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return messageInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		if(null == convertView){
			view = View.inflate(activity, R.layout.my_message_listview_item, null);
		}else {
			view = convertView;
		}
		msg_title_tv = (TextView)view.findViewById(R.id.message_title);
		msg_date_tv = (TextView)view.findViewById(R.id.message_push_time);
		msg_title_tv.setText(messageInfos.get(position).getTitle());
		String pushTime = messageInfos.get(position).getPushTime();
//		String str =  "2013-6-1 上午10:12:13";
		int index = pushTime.lastIndexOf("-") +3 ;
//		System.out.println(pushTime.substring(0, index).replaceAll("-", "/"));
		msg_date_tv.setText(pushTime.substring(0, index).replaceAll("-", "/"));
		return view;
	}

}
